var hidecolumn_arr = [];

function commonHiddenColumn(mainTable, itemNumInPerRow) {
    if (!itemNumInPerRow) {
        itemNumInPerRow = 5;
    }
    var tTable = $('#' + mainTable);
    var displays = "<table style='white-space: nowrap'><tr>";
    var targetColumns = []
    var columns = tTable.bootstrapTable("getVisibleColumns");
    var hideColumns = tTable.bootstrapTable("getHiddenColumns");
    for (var i = 0; i < columns.length; i++) {
        if (columns[i].title != undefined) {
            targetColumns.push(columns[i]);
        }
    }
    for (var j = 0; j < hideColumns.length; j++) {
        targetColumns.push(hideColumns[j]);
    }
    var length = targetColumns.length;
    if (length == 0) return;
    //生成展示数据
    for (var i = 1; i <= length; i++) {
        var perColumn = targetColumns[i - 1];
        var item = perColumn.field;
        var itemDisplay = perColumn.title;
        itemDisplay = itemDisplay.replace(/<br\/>/g, "");//去除标题中的换行符
        displays += "<td><input tableName='" + mainTable + "' name='columnfield' type='checkbox'   onclick=check(this) value='" + item + "'>" + itemDisplay + "</td>";
        if ((i % itemNumInPerRow == 0)) {
            displays += "</tr>"
            if (i != (length)) {
                displays += "<tr>";
            }
            continue;
        }
        if (i == length) {
            displays += "</tr>";
        }
    }
    displays += "</table>"
    $("#chooseHide").html(displays);
    for (var i = 0; i < hidecolumn_arr.length; i++) {
        $("[name='columnfield'][value='" + hidecolumn_arr[i] + "']").attr('checked', true);
    }
    $("#hideModal").modal("show");
}

//隐藏列并保存用户的选择
function check(para) {
    var columnfield = para.value;
    if ($(para).is(":checked")) {
        $("#" + $(para).attr("tableName")).bootstrapTable('hideColumn', columnfield);
        hidecolumn_arr.push(columnfield);
        return;
    }
    $("#" + $(para).attr("tableName")).bootstrapTable('showColumn', columnfield);
    for (var i = 0; i < hidecolumn_arr.length; i++) {
        if (hidecolumn_arr[i] == columnfield) {
            hidecolumn_arr.splice(i, 1);
        }
    }
}

function productTypeConvert(pid) {
    return {
        "1": "移动",
        "2": "联通",
        "3": "电信",
        "15": "远特-信时空",
        "16": "迪信通-迪加",
        "20": "蜗牛-蜗牛移动",
        "300": "中石化",
        "310": "中石油",
        "302": "中石化无卡号",
        "303": "中石油无卡号",
        "99": "虚拟运营商"

    }[pid];
}

function agentNo(pid) {
    return {
        "14165": "H",
        "13950": "H",
        "13630": "D",
        "14350": "D",
        "18370": "D"
    }[pid];
}

//备注
function _getCardFailReason(v) {
    return {
        "17016": "已达到当日提交上限",
        "18006": "产品相关供货价格不符",
        "21001": "卡密失败次数过多",
        "21002": "商户未设置密钥",
        "21003": "商户编码对应的商户不存在",
        "21004": "商户状态无效",
        "21005": "卡号或卡密解密无效",
        "21006": "未开通的产品",
        "21007": "商户编号为空",
        "21008": "请求参数无效",
        "21009": "数据签名无效",
        "21010": "不支持的卡面值",
        "21011": "不支持的业务类型",
        "21012": "卡种为空",
        "21013": "电信地方卡不支持",
        "21014": "卡密码失效",
        "21015": "相同卡密正在处理中",
        "21016": "商户未设置费率",
        "21017": "卡号卡密规则有误",
        "21018": "请求号重复",
        "21019": "请求IP无效",
        "21020": "相同卡号在平台成功过",
        "21021": "卡状态预判初始或锁定或保留",
        "23000": "销卡成功",
        "23001": "卡密码错误",
        "23002": "卡密码失效",
        "23003": "销卡失败",
        "23005": "未尝试销卡",
        "23006": "订单处理中",
        "23007": "提交面值与预判面值不符",
        "17011": "卡号已经成功过",
        "17012": "卡密码失效",
        "17010": "销卡地区和发行不匹配",
        "81007": "产品不存在",
        "81008": "产品未上架",
        "81009": "产品折扣未配置",
        "81010": "销卡模板未开启",
        "81011": "销卡模板或者产品未开启",
        "17013": "获取不到充值卡发行地区",
        "90998": "无卡号规则有误",
        "18004": "卡号卡密规则有误",
        "22000": "试充面值不符,暂停",
        "9999": "未知异常",
        "17023": "该产品尚未配置密价",
        "30029": "产品维护"
    }[v]
}

//状态
function convertStatus(v) {
    return {
        0: "在售",
        1: "已售",
        2: "停售",
        3: "可售",
        50: "补结算",
        5: "预判面值不符",
        4: "未预判面值",
        7: "等待慢速试充",
        8: "慢速试充",
        9: "待结算",
        10: "纠纷中"
    }[v];
}

//状态
function qbStatus(v) {
    return {
        0: "处理中",
        1: "成功",
        2: "失败",
        3: "异常"
    }[v];
}

//实名认证状态
function authenticationStatus(v) {
    return {
        0: "未认证",
        1: "认证成功",
        2: "认证失败",
        3: "认证中",
    }[v];
}

//闲鱼状态
function xianyuOrderStatus(v) {
    return {
        1: "订单创建",
        3: "已质检",
        5: "交易完成",
        103: "交易关闭",
        20: "转账成功",
        21: "转账失败",
        7: "已评价"
    }[v];
}

//闲鱼转账状态
function xianyuTransferOrderStatus(v) {
    return {
        5: "转账成功",
        7: "转账成功",
        20: "转账成功",
        21: "转账失败"
    }[v];
}

//转账申请状态
function xianyuTransferAgainOrderStatus(v) {
    return {
        0: "申请中",
        1: "审核成功",
        2: "审核失败"
    }[v];
}

function transferStatus(v) {
    return {
        "UN_TRANSFER": "未转账",
        "SUCCESS": "转账成功",
        "FAILED": "转账失败",
        "ABNORMAL": "转账异常"
    }[v];
}

//产品状态
function productStatus(v) {
    return {
        "ON": "<span style='color:green'>上架</span>",
        "OFF": "<span style='color:red'>下架</span>"
    }[v];
}

//闲鱼状态
function spuStatus(v) {
    return {
        0: "<span style='color:green'>上架</span>",
        1: "<span style='color:red'>下架</span>"
    }[v];
}

//提交类型
function submitType(v) {
    return {
        0: "上传图片",
        1: "展示卡密",
        2: "二维码+链接"
    }[v];
}

/**
 * 补结算状态
 * @param v
 * @returns {*}
 */
function transferStatusByManualClearing(v) {
    return {
        "1": "补结算成功",
        "2": "补结算失败",
        "3": "补结算异常"
    }[v];
}

//渠道
function qbChannel(v) {
    return {
        1: "软件",
        2: "网页"
    }[v];
}

//Q币大额权限
function qbLargeAmountConfig(v) {
    return {
        0: "关闭",
        1: "自动配置",
        2: "手动配置"
    }[v];
}

//Q币黑名单状态
function qbBlackType(v) {
    return {
        1: "正常",
        2: "其他",
        3: "黑名单"
    }[v];
}

//按钮权限
function buttonShiro(v) {
    $.ajax({
        type: "GET",
        url: "/adminButton/getBtnShiro",
        dataType: "json",
        success: function (data) {
            // console.log(data);
            if (data.success) {
                $("#" + v).show();
            } else {
                $("#" + v).hide();
            }
        }
    });
}

//销卡状态枚举类
var SupplyCardStatus = {
    "0": "待分配",
    "1": "分配成功",
    "2": "销卡成功",
    "3": "销卡失败",
    "4": "异常"
}

//销卡状态枚举类
var userPriceState = {
    "0": "下架",
    "1": "上架",
}

function format(shijianchuo) {

    if (shijianchuo == null || shijianchuo == '') {
        return '--';
    }
//shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}

//权限/状态枚举类
var userStatus = {
    "0": "<span style='color:red;'>关闭</span>",
    "1": "<span style='color:#005200;'>开启</span>"
}

//供卡申请
var submitCardApplyObj = {
    "INIT": {
        "color": "#357ebd",
        "font": "未申请"
    },
    "AUDITING": {
        "color": "#FF9900",
        "font": "审核中"
    },
    "SUCCESS": {
        "color": "#54A754",
        "font": "审核成功"
    },
    "FAIL": {
        "color": "#f56c6c",
        "font": "审核失败"
    }
}

//实名认证等级
var userCertificateLevel = {
    "0": "未认证",
    "1": "一级认证",
    "2": "二级认证",
    "3": "三级认证",
    "4": "四级认证"
}
//银行卡状态
var bankState = {
    "0": "关闭",
    "1": "开启"
}
//实名认证状态
var userCertificateStatus = {
    "0": "<span>未认证</span>",
    "5": "<span style='color:red'>认证中</span>",
    "6": "<span>认证成功</span>",
    "7": "<span>认证失败</span>",
    "8": "<span>处理中</span>"
}
//用户来源
var userType = {
    "0": "web",
    "1": "微信",
    "2": "app",
    "3": "易缴费"
}
//运营商
var operatorFun = {
    "1": "移动",
    "2": "联通",
    "3": "电信",
    "15": "远特",
    "16": "迪信通",
    "20": "蜗牛",
    "300": "中石化",
    "302": "中石化无卡号",
    "310": "中石油"
}

var productStatusFun = {
    "0": "<span style='color:red'>下架</span>",
    "1": "<span style='color:green'>上架</span>",
    "2": "<span style='color:#f36b11'>维护</span>"
}

var cecretPriceStatusFun = {
    "1": "<span style='color:green'>上架</span>",
    "0": "<span style='color:red'>下架</span>",
}
var submitTypeFun = {
    "0": "上传图片",
    "1": "展示卡密",
    "2": "二维码+链接"
}
var applyTypeFun = {
    "0": "供卡余额提现",
    "2": "佣金提现"
}
var withdrawChannel = {
    "alipay": "支付宝",
    "bank": "银行卡",
    "返佣": "返佣",
    "补差额": "补差额",
    "补结算": "补结算",
    "补手续费": "补手续费",
    "补扣款": "补扣款",
    "手动退款": "手动退款"
}
var withdrawStateFun = {
    "0": "待获取",
    "1": "处理中",
    "2": "成功",
    "3": "<span style='color:red'>失败</span>",
    "4": "<span style='color:#f3970a'>异常</span>",
    "5": "返销"
}

var auditStateFun = {
    "0": "待审核",
    "1": "审核通过",
    "2": "审核失败"
}
var withdrawLogState = {
    "0": "无",
    "1": "审核成功",
    "2": "审核失败",
    "3": "再次转账",
    "4": "置失败",
    "5": "置成功",
    "6": "置异常",
    "7": "成功处理失败"
}
//加油卡地区
var zone = ["全国", "湖南", "湖北", "广东", "深圳", "广西", "河南", "河北", "山东", "山西", "江西", "江苏", "浙江", "黑龙江", "新疆", "云南", "贵州", "福建", "吉林", "安徽", "四川", "西藏", "宁夏", "辽宁", "青海", "甘肃", "陕西", "内蒙古", "北京", "上海", "天津", "重庆", "海南"];
var zoneNoCountry = ["湖南", "湖北", "广东", "深圳", "广西", "河南", "河北", "山东", "山西", "江西", "江苏", "浙江", "黑龙江", "新疆", "云南", "贵州", "福建", "吉林", "安徽", "四川", "西藏", "宁夏", "辽宁", "青海", "甘肃", "陕西", "内蒙古", "北京", "上海", "天津", "重庆", "海南"];

function initArea() {
    var str = '';
    for (var i = 0; i < zoneNoCountry.length; i++) {
        str += '<option   value="' + zoneNoCountry[i] + '">' + zoneNoCountry[i] + '</option>';
    }
    $("#area").append(str);
}

//消费类型
var consumeType = {
    "1": '<span>结算</span>',
    "2": '<span>审核中</span>',
    "3": '<span>失败补回</span>',
    "4": '<span>提现成功</span>',
    "5": '<span>提现失败</span>',
    "6": '<span>返佣</span>',
    "7": '<span>补结算</span>',
    "8": '<span>补差额</span>',
    "9": '<span>提现手续费</span>',
    "10": '<span>提现手续费失败</span>',
    "11": '<span>补手续费</span>',
    "13": '<span>补扣款</span>',
    "12": '<span>手动退款</span>'
}

function roleCheck() {
    var superAdmin = 0;
    $.ajax({
        type: "GET",
        url: "/AdminInterface/queryAdminRole",
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.success) {
                superAdmin = 1;
            }
        }
    });
    return superAdmin;
}

//会员编号隐藏
function userAccountHidden(value, idKey) {
    if (value == null || value == '' || value == '-') {
        return value;
    }
    return "<span id='account_field" + idKey + "' type='button'>" + value.substring(0, 3) + "****" + value.substring(7, 11) + "</span>";
}

//复制
function copyAddon(v) {
    return "<span class='text-info' onclick='copyFlowNo(this)' data-field='" + v + "' style='display: inline-flex'><i class='fa fa-clipboard'   style='font-size: 12px'></i></span>";
}

function copyFlowNo(obj) {
    var text = $(obj).attr("data-field");
    var tag = document.createElement('input');
    tag.setAttribute('id', 'cp_hgz_input');
    tag.value = text;
    document.getElementsByTagName('body')[0].appendChild(tag);
    document.getElementById('cp_hgz_input').select();
    document.execCommand('copy');
    document.getElementById('cp_hgz_input').remove();
    layer.msg("已复制到剪贴板");
}
